package com.jt.www.util;

import javax.mail.internet.MimeUtility;
import java.io.ByteArrayOutputStream;
import java.io.OutputStream;

/**
 * @author xq.wu03
 * @Classname Base64
 * @Description 诚泰电子保单
 * @create 2020-10-23 16:36
 */
public class Base64 {

    public static byte[] encode(byte[] b) throws Exception {
        ByteArrayOutputStream baos = null;
        OutputStream b64os = null;
        try {
            baos = new ByteArrayOutputStream();
            b64os = MimeUtility.encode(baos, "base64");
            b64os.write(b);
            b64os.close();
            return baos.toByteArray();
        } catch (Exception e) {
            throw new Exception(e);
        } finally {
            try {
                if (baos != null) {
                    baos.close();
                    baos = null;
                }
            } catch (Exception e) {
            }
            try {
                if (b64os != null) {
                    b64os.close();
                    b64os = null;
                }
            } catch (Exception e) {
            }
        }
    }
}
